<?php
	if(!isset($_REQUEST['ajax'])){ $_REQUEST['ajax'] = "";}
	if($_REQUEST['ajax']!=true) include 'header.tpl.php';
?>
	<h2><?php echo $this->language['calendar_task'];?></h2>
	<div class="row">
		<div class="col-lg-9">
			<ul class="shortcut-buttons-set">
				<li>
					<a class="shortcut-button" href='#calendar'><span>
					<i class="aicon-calendar_work"></i>
					<?php echo $this->language['calendar_task'];?></span></a>
				</li>
				<?php if(check_permission('calendar_view_project')){ ?>
				<li>
					<a class="shortcut-button" href='#calendar/mod=project'><span>
					<i class="aicon-calendar_cog"></i>
					<?php echo $this->language['calendar_project'];?></span></a>
				</li>
				<?php } ?>
			</ul>
		</div>
		<div class="col-lg-3">
			<img src='resources/images/note.png' alt="<?php echo $this->language['note'];?>" />
		</div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<div class="gantt"></div>
		</div>
	</div>
	<script type="text/javascript" src="resources/scripts/jquery.gantt.min.js"></script>
	<script type="text/javascript">
		$(function() {
			$(".gantt").gantt({
				source: [
					<?php if(count($this->rows)>0){?>
					<?php for($i = 0;$i < count($this->rows);$i++){?>
					{
						name: "<?php echo htmlspecialchars($this->rows[$i]['name'],ENT_QUOTES);?>",
						desc: "<?php echo htmlspecialchars($this->rows[$i]['desc'],ENT_QUOTES);?>",
						values: [{
							from: "/Date(<?php echo strtotime(date("m/d/Y",$this->rows[$i]['start_time']))*1000;?>)/",
							to: "/Date(<?php echo strtotime(date("m/d/Y",$this->rows[$i]['end_time']))*1000;?>)/",
							label: "<?php echo htmlspecialchars($this->rows[$i]['label'],ENT_QUOTES);?>",
							customClass: "<?php
								if($this->rows[$i]['status'] == 0) echo "ganttRed";
								elseif($this->rows[$i]['status'] == -1) echo "ganttGray";
								elseif($this->rows[$i]['status'] == 1) echo "ganttOrange";
								elseif($this->rows[$i]['status'] == 2) echo "ganttGreen";
								elseif($this->rows[$i]['status'] == 3) echo "ganttBlue";
								else echo "ganttGray";
								?>",
							dataObj: {id:<?php echo $this->rows[$i]['id'];?>}
						}]
					}<?php echo ($i < count($this->rows)) ? ",":"";?>
					<?php }}else{ ?>
					{
						name: "",
						values: [{
							from: "/Date(<?php echo strtotime("-2 weeks",time())*1000;?>)/",
							to: "/Date(<?php echo strtotime("+2 weeks",time())*1000;?>)/",
							label: "<?php echo $this->language['calendar_empty'];?>",
							customClass: "ganttRed"
						}]
					}
					<?php } ?>
				],
				navigate: "scroll",
				scale: "days",
				maxScale: "months",
				minScale: "days",
				itemsPerPage: 50,
				months:["Tháng 1", "Tháng 2", "Tháng 3", "Tháng 4", "Tháng 5", "Tháng 6", "Tháng 7", "Tháng 8", "Tháng 9", "Tháng 10", "Tháng 11", "Tháng 12"],
				waitText:"Loading....",
				onItemClick: function(data) {
					<?php if(isset($_GET['mod']) && $_GET['mod'] == 'project'){ ?>
					window.location.hash = 'project_view/pid='+data.id;
					<?php }else{ ?>
					window.location.hash = 'task_view/tid='+data.id;
					<?php } ?>
    				e.preventDefault();
				}
			});
		});
	</script>
<?php if(isset($this->breadcrumb) && isset($this->title_header)):?>
	<script type="text/javascript">
		$(function() {
			$("#title-header").text('<?php echo $this->title_header;?>');
			$("#breadcrumb").html('<?php echo build_breadcrumb($this->breadcrumb);?>');
		});
	</script>
<?php endif;?>
<?php
	if($_REQUEST['ajax']!=true) include 'footer.tpl.php';
?>